package read

import (
	"log"

	"github.com/spf13/viper"
)

type ReadYaml struct {
	reader *viper.Viper
}

func NewReader() *ReadYaml {
	reader := viper.New()
	reader.SetConfigType("yaml")
	reader.SetConfigName("config")
	reader.AddConfigPath("./")
	err := reader.ReadInConfig()
	if err != nil {
		log.Panicf("初始化reader错误:%v", err)
	}
	return &ReadYaml{reader}
}
func (readYaml *ReadYaml) ReadJustPiece(k string, v interface{}) error {
	err := readYaml.reader.UnmarshalKey(k, v)
	if err != nil {
		return err
	}
	return nil
}
